home *** CD-ROM | disk | FTP | other *** search
- {****************************************************************************}
- {* *}
- {* UNIT: ProgErr and ProgErrX (PROGERR.PAS) *}
- {* *}
- {* Donated to the Public Domain 5/20/91 by Dan Thomas CIS: 72301,2164 *}
- {* *}
- {* Purpose: *}
- {* *}
- {* This procedure will be called when TURBO encounters an I/O error *}
- {* (if I/O error detection is disabled) or a run time error. It will *}
- {* display an appropriate error message. *}
- {* *}
- {* ProgErr Uses: CRT -- ProgErrX does not! *}
- {* *}
- {* Required: *}
- {* *}
- {* During the use of SORT.BOX (which sometimes causes a run time *}
- {* error), set PROGRAM_ERROR_DURING_SORT to true (and re-set it *}
- {* after the sort). An appropriate error message will be displayed. *}
- {* *}
- {* In addition to the above, you may call PROGRAM_I_O_ERROR passing *}
- {* it the IOResult code, and the ID of the file that the error *}
- {* occurred on. An appropriate message will be displayed, and the *}
- {* program halted. *}
- {* *}
- {* Another procedure available is FATAL_ERROR. Pass it en error *}
- {* message. It will terminate the program. *}
- {* *}
- {* A function that is available is ERROR_DESC. Pass it the IOResult *}
- {* code, and it will return a descriptive message. *}
- {* *}
- {****************************************************************************}
-
- UNIT PROGERR;
-
- INTERFACE
- {============================================================================}
-
- USES CRT;
-
- CONST
- program_error_during_sort : boolean = false;
-
- PROCEDURE PROGRAM_I_O_ERROR(error_nbr : integer;
- file_id : string);
-
- PROCEDURE FATAL_ERROR(msg : string);
-
- FUNCTION ERROR_DESC(error_nbr : integer) : string;
-
- {============================================================================}
- IMPLEMENTATION
-
- VAR
- save_exitproc : pointer;
-
- PROCEDURE RESET_SCREEN;
-
- begin
- Window(1,1,80,25);
- GotoXY(1,25);
- writeln;
- end; {reset_screen}
-
- PROCEDURE FATAL_ERROR(msg : string);
-
- begin
- reset_screen;
- writeln(^G,'Fatal error: ',msg);
- halt(1);
- end; {fatal_error}
-
- FUNCTION ERROR_DESC(error_nbr : integer) : string;
-
- var
- s : string;
-
- begin
- case error_nbr of
- 2 : error_desc := 'File not found';
- 3 : error_desc := 'Path not found';
- 4 : error_desc := 'Too many open files';
- 5 : error_desc := 'Access denied';
- 16 : error_desc := 'Cannot remove current directory';
- 17 : error_desc := 'Cannot rename accross drives';
- 100 : error_desc := 'Disk read error';
- 101 : error_desc := 'Disk write error';
- 106 : error_desc := 'Invalid numeric format';
- 150 : error_desc := 'Disk is write-protected';
- 152 : error_desc := 'Drive not ready';
- 154 : error_desc := 'CRC error in data';
- 156 : error_desc := 'Disk seek error';
- 158 : error_desc := 'Sector not found';
- 159 : error_desc := 'Printer out of paper';
- 160 : error_desc := 'Device write fault';
- 161 : error_desc := 'Device_read_fault';
- 162 : error_desc := 'Hardware failure';
- 200 : error_desc := 'Division by zero';
- 202 : error_desc := 'Stack overflow';
- 203 : error_desc := 'Heap overflow (not enough memory)';
- 205 : error_desc := 'Floating point overflow';
- 206 : error_desc := 'Floating point underflow';
- 207 : error_desc := 'Invalid floating point operation';
- else
- str(error_nbr,s);
- error_desc := 'Error number ' + s;
- end; {of case}
- end; {error_desc}
-
- PROCEDURE PROGRAM_I_O_ERROR(error_nbr : integer;
- file_id : string);
-
- begin
- reset_screen;
- if file_id = '' then
- writeln(^G,'I/O error = ',error_desc(error_nbr))
- else
- writeln(^G,'I/O error on file ',file_id,': ',error_desc(error_nbr));
- halt(error_nbr);
- end; {program_i_o_error}
-
- PROCEDURE PROCESS_I_O_ERROR;
-
- begin
- writeln(^G,'I/O error = ',error_desc(ExitCode));
- end; {process_i_o_error}
-
- PROCEDURE PROCESS_RUN_TIME_ERROR;
-
- begin
- writeln(^G,'Run time error = ',error_desc(ExitCode));
- end; {process_run_time_error}
-
- {$f+}
- PROCEDURE PROGRAM_ERROR;
-
- begin
- ExitProc := save_exitproc;
- if (ExitCode <> 0) and (ErrorAddr <> nil) then
- begin
- reset_screen;
- if ExitCode < 200 then
- process_i_o_error
- else
- process_run_time_error;
- ErrorAddr := nil;
- end;
- end; {program_error}
- {$f-}
-
-
- begin {initialization}
- save_exitproc := ExitProc;
- ExitProc := @program_error;
- end.
-